
#ifndef TEXTEDIT_H
#define TEXTEDIT_H

//{{{ file documentation -------------------------------------------------------

/*!
 * @file     textedit.h
 * @brief    dicodor text edition widget class declaration
 */

//}}} --------------------------------------------------------------------------
//{{{ includes / predeclarations -----------------------------------------------

#include "hspell.h"
#include "tools.h"
#include "config.h"

#include <QtGui/QTextDocument>
#include <QtCore/QStringList>

#include <QtGui/QTextEdit>
#include <QtGui/QMenu>
#include <QtGui/QContextMenuEvent>
#include <QtCore/QMap>

//}}} --------------------------------------------------------------------------
//{{{ structures ---------------------------------------------------------------
//}}} --------------------------------------------------------------------------
//{{{ .TextEdit ----------------------------------------------------------------

class TextEdit:		public QTextEdit
{
	Q_OBJECT

private:
	QMap <QString, QString>	m_toReplace;

	void			normalizeText ();
	void			createCharMenu ();

public:
	explicit		TextEdit (QWidget * parent = 0);
	virtual			~TextEdit();
	void			setConfig (Config* config) { m_config = config; setFont (m_config->optionDefaultFont ()); }
	bool			isEmpty () { return m_doc->isEmpty (); }

	void			contextMenuEvent (QContextMenuEvent * event);

signals:
	void			documentModified (bool m);
	void			documentIsEmpty (bool b);
	void			message (const QString & msg);

public slots:
	void			onDocContentsChange (int, int, int);
	void			forceUpdate ()		{ onDocContentsChange (0,0,0); }
	bool			open (const QString &path);
	bool			saveAs (const QString &path);
	bool            saveAs (const QString &path, const QByteArray &format);

private:	// variables members

	HSpell			m_spell;
	QMenu			* m_charMenu;
	QTextDocument	* m_doc;
	Config			* m_config;

	enum {
		MenuSuggestion = 0,
		MenuAlwaysReplace,
		MenuAddToDic,
		MenuSkip,
		MenuDelete
	};

private:	// functions

};

//}}} --------------------------------------------------------------------------

#endif // TEXTEDIT_H

